// FileLogging.h: interface for the CFileLogging class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_FILELOGGING_H__8E3D3228_90C5_4EBC_A2D2_DED5CEE60CC0__INCLUDED_)
#define AFX_FILELOGGING_H__8E3D3228_90C5_4EBC_A2D2_DED5CEE60CC0__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <stdio.h>
#include <time.h>
#include <sys\timeb.h>

extern const char * gpLogFile;

class CFileLogging  
{
public:
	CFileLogging * GetFileLogging() {
		if (NULL == _singleton)
			_singleton = new CFileLogging;
		return _singleton;
	}
	static void WriteToFile(const char * message, bool releaseLog = FALSE) {

#ifdef _RELEASE
	if (!releaseLog)
	return;
#endif

	FILE * fp = fopen(gpLogFile, "a+");
	if (NULL != fp) {

	TCHAR subj[MAX_PATH*2] = "";
	time_t timePoint;
	struct _timeb timebuffer;
	char *timeline;
	char *temp = (char*)message;

	_ftime( &timebuffer );
	timePoint = timebuffer.time;
	timeline = ctime( & ( timebuffer.time ) );
	sprintf(subj, "%.19s.%hu :: ", timeline,
	timebuffer.millitm);
	strcat(subj, temp);
	strcat(subj, "\n");

	fwrite(subj, 1, strlen(subj), fp);
	fclose(fp);
}

	}
protected:
	CFileLogging();
	virtual ~CFileLogging();
private:
	static CFileLogging * _singleton;
};

#endif // !defined(AFX_FILELOGGING_H__8E3D3228_90C5_4EBC_A2D2_DED5CEE60CC0__INCLUDED_)
